﻿using Future.Common.Enum;

namespace Future.Common.Models
{
    /// <summary>
    /// 描述：返回结果包装类
    /// 创建人： yangkai
    /// 创建时间：2022/11/8 15:56:26
    /// </summary>
    public class ResultVo
    {
        /// <summary>
        /// 状态码
        /// </summary>
        public ResultCodeEnum Code { get; set; }

        /// <summary>
        /// 请求结果
        /// </summary>
        public bool Status { get; set; }

        /// <summary>
        /// 提示信息
        /// </summary>
        public string Message { get; set; } = string.Empty;

        /// <summary>
        /// 数据结果
        /// </summary>
        public object Data { get; set; } = default!;

        /// <summary>
        /// 登录过期
        /// </summary>
        /// <param name="code"></param>
        /// <param name="msg"></param>
        /// <returns></returns>
        public static ResultVo Expire(ResultCodeEnum code = ResultCodeEnum.AccessTokenExpire, string msg = "")
        {
            return new ResultVo() { Code = code, Status = false, Message = msg };
        }

        /// <summary>
        /// 操作失败
        /// </summary>
        /// <param name="msg"></param>
        /// <returns></returns>
        public static ResultVo Fail(string msg = "")
        {
            return new ResultVo() { Code = ResultCodeEnum.NotSuccess, Status = false, Message = msg };
        }

        /// <summary>
        /// 操作失败
        /// </summary>
        /// <param name="resultCodeEnum"></param>
        /// <param name="msg"></param>
        /// <returns></returns>
        public static ResultVo Fail(ResultCodeEnum resultCodeEnum, string msg = "")
        {
            return new ResultVo() { Code = resultCodeEnum, Status = false, Message = msg };
        }

        /// <summary>
        /// 操作成功
        /// </summary>
        /// <param name="msg"></param>
        /// <returns></returns>
        public static ResultVo Success(string msg = "")
        {
            return new ResultVo() { Code = ResultCodeEnum.Success, Status = true, Message = msg };
        }

        /// <summary>
        /// 操作成功
        /// </summary>
        /// <param name="data"></param>
        /// <param name="msg"></param>
        /// <returns></returns>
        public static ResultVo Success(object data, string msg = "")
        {
            return new ResultVo() { Code = ResultCodeEnum.Success, Status = true, Message = msg, Data = data };
        }

        /// <summary>
        /// 没有权限
        /// </summary>
        /// <param name="msg"></param>
        /// <returns></returns>
        public static ResultVo UnAuthorize(string msg = "")
        {
            return new ResultVo() { Code = ResultCodeEnum.NoPermission, Status = false, Message = msg };
        }
    }

    public class ResultVo<T> : ResultVo where T : class, new()
    {
        /// <summary>
        /// 数据结果
        /// </summary>
        public new T Data { get; set; } = default!;

        public static ResultVo<T> Success(T data, string msg = "")
        {
            return new ResultVo<T>() { Code = ResultCodeEnum.Success, Status = true, Message = msg, Data = data };
        }
    }
}
